package com.itheima.d4_collections;

import java.util.ArrayList;
import java.util.Collections;

/**
 * 目标：掌握Collections集合工具类的使用。
 */
public class CollectionsTest1 {
    public static void main(String[] args) {
        // 1、public static <T> boolean addAll(Collection<? super T> c, T...elements)：为集合批量添加数据
        ArrayList<String> names = new ArrayList<>();
        names.add("张无忌");
        names.add("张无");
        names.add("小赵");

        ArrayList<String> otherNames = new ArrayList<>();
        otherNames.add("赵敏");
        otherNames.add("小丢");
        otherNames.add("小周");

        names.addAll(otherNames);
        System.out.println("otherNames = " + otherNames);

        Collections.addAll(names,"哈哈哈哈","hhhh");
        System.out.println("names = " + names);
        // 2、public static void shuffle(List<?> list)：打乱List集合中的元素顺序。
        Collections.shuffle(otherNames);
        System.out.println("otherNames = " + otherNames);

        // 3、 public static <T> void sort(List<T> list)：对List集合中的元素进行升序排序。
        Collections.sort(otherNames);
        System.out.println("otherNames = " + otherNames);
        // 4、public static <T> void sort(List<T> list， Comparator<? super T> c): 对List集合中元素，按照比较器对象指定的规则进行排序
        Collections.sort(names,((o1, o2) -> o2.compareTo(o1)));
        System.out.println("names = " + names);
    }
}
